<template>

  <el-tabs v-model="activeName" @tab-click="handleClick">
    <el-tab-pane  label="总售出金额占比" name="first">
      <div  id="myChart" :style="{width: '1000px', height: '600px'}"></div>
    </el-tab-pane>
    <el-tab-pane  label="近半年售出金额占比" name="second">
      <div  id="myChart_sixMonth" :style="{width: '1000px', height: '600px'}"></div>
    </el-tab-pane>
    <el-tab-pane label="近30天售出金额占比" name="third">
      <div  id="myChart_nowMonth" :style="{width: '1000px', height: '600px'}"></div>
    </el-tab-pane>
    <el-tab-pane label="今日销售金额占比" name="fourth">
      <div  id="myChart_today" :style="{width: '1000px', height: '600px'}"></div>
    </el-tab-pane>
  </el-tabs>


</template>

<script>
import request from "../../utils/request";

export default {
  name: "Statistics",
  data(){
    return{
      activeName:'first'


    }
  },
  mounted() {
    this.drawLine()
    this.drawLineSixMonth()
    this.drawLinenowMonth()
    this.drawLinetoday()
  },
  methods:{

    drawLine() {


      // 基于准备好的dom，初始化echarts实例
      let myChart = this.$root.echarts.init(document.getElementById('myChart'))
      let option = {
        title: {
          text: '各菜品售出金额(元)￥',

          subtext: '所有售出菜品',
          left: 'left'
        },
        tooltip: {
          trigger: 'item'
        },
        legend: {
          trigger: 'item'
        },
        toolbox: {
          show: true,
          feature: {
            mark: {show: true},
            dataView: {show: true, readOnly: false},
            restore: {show: true},
            saveAsImage: {show: true}
          }
        },
        series: [
          {
            name: '销售比例',
            type: 'pie',
            radius: [50, 250],
            center: ['50%', '50%'],
            roseType: 'area',
            itemStyle: {
              borderRadius: 8
            },
            data: []
          }
        ]
      }

      request.get("/Statistics/selectInfo").then(res => {

        res.data.forEach(item => {


          option.series[0].data.push({name: item.key, value: item.value})
        })

        // 绘制图表
        myChart.setOption(option);
      })
    },
    drawLineSixMonth() {


      // 基于准备好的dom，初始化echarts实例
      let myChart = this.$root.echarts.init(document.getElementById('myChart_sixMonth'))
      let option = {
        title: {
          text: '各菜品售出金额(元)￥',

          subtext: '所有售出菜品',
          left: 'left'
        },
        tooltip: {
          trigger: 'item'
        },
        legend: {
          trigger: 'item'
        },
        toolbox: {
          show: true,
          feature: {
            mark: {show: true},
            dataView: {show: true, readOnly: false},
            restore: {show: true},
            saveAsImage: {show: true}
          }
        },
        series: [
          {
            name: '销售比例',
            type: 'pie',
            radius: [50, 250],
            center: ['50%', '50%'],
            roseType: 'area',
            itemStyle: {
              borderRadius: 8
            },
            data: []
          }
        ]
      }

      request.get("/Statistics/selectInfo_sixMonth",).then(res => {

        res.data.forEach(item => {


          option.series[0].data.push({name: item.key, value: item.value})
        })

        // 绘制图表
        myChart.setOption(option);
      })
    },
    drawLinenowMonth() {


      // 基于准备好的dom，初始化echarts实例
      let myChart = this.$root.echarts.init(document.getElementById('myChart_nowMonth'))
      let option = {
        title: {
          text: '各菜品售出金额(元)￥',

          subtext: '所有售出菜品',
          left: 'left'
        },
        tooltip: {
          trigger: 'item'
        },
        legend: {
          trigger: 'item'
        },
        toolbox: {
          show: true,
          feature: {
            mark: {show: true},
            dataView: {show: true, readOnly: false},
            restore: {show: true},
            saveAsImage: {show: true}
          }
        },
        series: [
          {
            name: '销售比例',
            type: 'pie',
            radius: [50, 250],
            center: ['50%', '50%'],
            roseType: 'area',
            itemStyle: {
              borderRadius: 8
            },
            data: []
          }
        ]
      }

      request.get("/Statistics/selectInfo_nowMonth",).then(res => {

        res.data.forEach(item => {


          option.series[0].data.push({name: item.key, value: item.value})
        })

        // 绘制图表
        myChart.setOption(option);
      })
    },
    drawLinetoday() {


      // 基于准备好的dom，初始化echarts实例
      let myChart = this.$root.echarts.init(document.getElementById('myChart_today'))
      let option = {
        title: {
          text: '各菜品售出金额(元)￥',

          subtext: '所有售出菜品',
          left: 'left'
        },
        tooltip: {
          trigger: 'item'
        },
        legend: {
          trigger: 'item'
        },
        toolbox: {
          show: true,
          feature: {
            mark: {show: true},
            dataView: {show: true, readOnly: false},
            restore: {show: true},
            saveAsImage: {show: true}
          }
        },
        series: [
          {
            name: '销售比例',
            type: 'pie',
            radius: [50, 250],
            center: ['50%', '50%'],
            roseType: 'area',
            itemStyle: {
              borderRadius: 8
            },
            data: []
          }
        ]
      }

      request.get("/Statistics/selectInfo_today",).then(res => {

        res.data.forEach(item => {


          option.series[0].data.push({name: item.key, value: item.value})
        })

        // 绘制图表
        myChart.setOption(option);
      })
    },



  },
}

</script>



<style scoped>

</style>